<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>03-06</title>
<script src="https://unpkg.com/vue/dist/vue.min.js"></script>
</head>
<body>
<div id="example">
    x : <input type='text' v-model="x" /><br />
    y : <input type='text' v-model="y" /><br />
    덧셈 결과 : {{sum}}
</div>
<script type="text/javascript">
var vm = new Vue({
    el : "#example",
    data : { x:0, y:0 },
    beforeUpdate : function() {
        console.log("before update")
        console.log(this.x);
    },
    updated : function() {
        console.log("update")
        console.log(this.x);
    },
    computed : {
        sum : function() {
            var result = Number(this.x) + Number(this.y);
            if (isNaN(result)) return  0;
            else return result;
        }
    }
})
</script>
</body>
</html>